home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / X / Xserver / tulip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.5 KB  |  102 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* $Revision: 1.3 $ */
  18. /*
  19.  * tulip - Turns root cursor into three-color tulip.
  20.  *         COMPILE: cc -o tulip tulip.c -lXext -lX11_s
  21.  */
  22.  
  23. #include <X11/Xlib.h>
  24. #include <X11/extensions/SGIMisc.h>
  25.  
  26. /*
  27.  * Basis for constructing a three color cursor:
  28.  *
  29.  * Cursor plane 0 is date ("foreground")
  30.  * Cursor plane 1 is mask ("background")
  31.  *
  32.  * X server color display truth table:
  33.  *   mask(bit1) source(bit0)  color
  34.  *        0        0          transparent
  35.  *        0        1          third color
  36.  *        1        0          background
  37.  *        1        1          foreground
  38.  *
  39.  * WARNING: Not all SGI hardware supports three-color cursors (ie,
  40.  *          early Personal IRIS models).
  41.  */
  42.  
  43. /*
  44.  * Tulip 16x16 bitmaps (foreground and background) generated via bitmap.
  45.  */
  46.  
  47. #define tulip_fg_width 16
  48. #define tulip_fg_height 16
  49. static char     tulip_fg_bits[] = {
  50.     0x00, 0x00, 0x04, 0x20, 0x5c, 0x3a, 0xf8, 0x1f, 0xf0, 0x0f, 0xe0, 0x07,
  51.     0xc0, 0x01, 0x80, 0x00, 0x80, 0x00, 0x9c, 0x1e, 0xbc, 0x1f, 0xf8, 0x0f,
  52.     0xb0, 0x06, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00};
  53.  
  54. #define tulip_bg_width 16
  55. #define tulip_bg_height 16
  56. static char     tulip_bg_bits[] = {
  57.     0x06, 0x60, 0x5e, 0x7a, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x0f,
  58.     0xe0, 0x07, 0x40, 0x01, 0x5c, 0x1f, 0x62, 0x21, 0x42, 0x20, 0x04, 0x10,
  59.     0x48, 0x09, 0x70, 0x07, 0x40, 0x01, 0x40, 0x01};
  60.  
  61. main()
  62. {
  63.     Display        *dpy;
  64.     Window          root;
  65.     Pixmap          fg_pixmap, bg_pixmap;
  66.     Cursor          cursor;
  67.     XColor          red, white, green;
  68.     Status          status;
  69.     Colormap        cmap;
  70.     int             dummy;
  71.  
  72.     dpy = XOpenDisplay(NULL);
  73.     if (dpy == NULL) {
  74.     fprintf(stderr, "tulip: could not open display\n");
  75.     exit(1);
  76.     }
  77.     if (!XSGIMiscQueryExtension(dpy, &dummy, &dummy)) {
  78.     fprintf(stderr, "tulip: SGI-SUNDRY-NONSTANDARD extension required\n");
  79.     exit(1);
  80.     }
  81.     root = DefaultRootWindow(dpy);
  82.     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
  83.     status = XParseColor(dpy, cmap, "orangered", &red);
  84.     status = status && XParseColor(dpy, cmap, "white", &white);
  85.     status = status && XParseColor(dpy, cmap, "darkgreen", &green);
  86.     if (status == 0) {
  87.     fprintf(stderr, "tulip: unable to parse colors\n");
  88.     exit(1);
  89.     }
  90.     fg_pixmap = XCreateBitmapFromData(dpy, root, tulip_fg_bits,
  91.                       tulip_fg_width, tulip_bg_height);
  92.     bg_pixmap = XCreateBitmapFromData(dpy, root, tulip_bg_bits,
  93.                       tulip_bg_width, tulip_bg_height);
  94.     cursor = XCreatePixmapCursor(dpy, fg_pixmap, bg_pixmap, &red, &white,
  95.                  tulip_fg_width / 2, tulip_bg_height / 2);
  96.     XSGIMiscSetThirdCursorColor(dpy, cursor, &green);
  97.     XDefineCursor(dpy, root, cursor);
  98.     XCloseDisplay(dpy);
  99.     printf("to restore: xsetroot -cursor_name X_cursor -fg red -bg white\n");
  100.     exit(0);
  101. }
  102.